package com.tjsinfo.tjsoa.worklog.action;

import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.system.vo.User;
import com.tjsinfo.tjsoa.worklog.bo.IWorkLogMainBo;
import com.tjsinfo.tjsoa.worklog.vo.WorkLogMain;

/**
 * 工作日志月历
 * @author wangxiaowei
 *
 */

public class WorkLogMonthModleAction extends Action{
	 protected IWorkLogMainBo workLogMainBo;
		
		
	public IWorkLogMainBo getWorkLogMainBo() {
		return workLogMainBo;
	}
	public void setWorkLogMainBo(IWorkLogMainBo workLogMainBo) {
		this.workLogMainBo = workLogMainBo;
	}
		/* (non-Javadoc)
		 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
		 */
		@Override
		public ActionForward execute(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response)
				throws Exception {
			// TODO Auto-generated method stub
			try {
				Date date = new Date();
				Map<Integer, WorkLogMain> map =	selectWorkLogYear("M", date, request);
				return forword(mapping, request, date, map);
			} catch (RuntimeException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				return mapping.findForward("error");
			}
		}
		/**
		 * 转发方法
		 * @param mapping
		 * @param request
		 * @param date
		 * @param map
		 * @return
		 */
		protected ActionForward forword(ActionMapping mapping,
				HttpServletRequest request, Date date, Map<Integer, WorkLogMain> map) {
			request.setAttribute("map", map);
			request.setAttribute("yueli", date);
			return mapping.findForward("ok");
		}
		/**
		 * 对于每个一年的工作计划进行查询
		 * @return map
		 */
		protected Map<Integer, WorkLogMain> selectWorkLogYear(String type, Date date,HttpServletRequest request) {
			HttpSession session = request.getSession();
			User user = (User)session.getAttribute("user");
			return   workLogMainBo.selectWorkLogTypeAndYearMAPNumber(type, date.getYear()+1900, user.getUser_id());
		}
}
